package com.example.manager.controller;

import com.example.manager.domain.Product;
import com.example.manager.pojo.Result;
import com.example.manager.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/products")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping
    public Result<List<Product>> selectProducts() {
        return productService.selectProducts();
    }

    @PostMapping
    public Result insertProduct(Product product) {
        return productService.insertProduct(product);
    }

    @PutMapping("/{product_id}")
    public Result updateProduct(Product product, @PathVariable Integer product_id) {
        product.setProduct_id(product_id);
        return productService.updateProduct(product);
    }

    @DeleteMapping("/{product_id}")
    public Result deleteProduct(@PathVariable Integer product_id) {
        return productService.deleteProduct(product_id);
    }
}
